import random
import time


class Tiger:
    name = "老虎"

    def __init__(self, w):
        self.w = w

    def roar(self):
        print("wow!!!wow!!!wow!!!")

    def food(self, feed):
        if feed == "meet":
            print("喂对了,体重加10斤")
            self.w += 10
        else:
            print("喂错了,体重减10斤")
            self.w -= 10


class Sheep:
    name = "山羊"

    def __init__(self, w):
        self.w = w

    def roar(self):
        print("miemiemie!!!")

    def food(self, feed):
        if feed == "grass":
            print("喂对了,体重加10斤")
            self.w += 10
        else:
            print("喂错了,体重减10斤")
            self.w -= 10


class Room:
    def __init__(self, num, animal):
        self.num = num
        self.animal = animal


# 定义一个列表，用于保存房间对象
rooms = []

for i in range(1, 11):
    flage = random.randint(0, 1)
    if flage == 0:
        a = Tiger(200)
    else:
        a = Sheep(100)
    # 实例化房间对象
    rooms.append(Room(i, a))

starttime = time.time()
while True:
    endtime = time.time()
    if endtime - starttime >= 2:
        for r in rooms:
            print(f'第{r.num}房间内的动物是{r.animal.name},动物体重是{r.animal.w}')
        break
    # 随机弹出一个房间
    r1 = random.choice(rooms)

    # 选择是否敲门
    f = input("请选择是否敲门，输入y:")
    if f == "y":
        # 调用敲门的实例方法
        r1.animal.roar()

    feed = input("请输入食物：")
    # 调用喂食的方法
    r1.animal.food(feed)
